package com.itheima.exception;

import com.itheima.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    // 统一处理所有的Exception异常
    @ExceptionHandler(Exception.class)
    public Result Exception(Exception ex) {
        return new Result(null,null,ex.getMessage());
    }
    // /**
    //  * 业务级别异常
    //  */
    // @ExceptionHandler(BusinessException.class)
    // public Result BusinessException(BusinessException ex) {
    //     return new Result(ex.getCode(),"业务出现异常",ex.getMessage());
    // }

    /**
     * 系统级别异常
     */
    @ExceptionHandler(SystemException.class)
    public Result SystemException(SystemException ex) {
        return new Result(ex.getCode(),"出现错误",ex.getMessage());
    }
}
